package sensimulator.intersection.lanes;

import java.awt.Point;
import java.awt.geom.Point2D;

/**
 * Used to define paths in lanes. Works as a linked list
 * @author Erwin
 *
 */
public class LaneNode {

	private Lane lane;
	
	private Point point;

	private LaneNode next;
	
	private boolean isTrafficLight;

	
	public LaneNode(Lane lane, Point point) { this(lane, point, false); }
	
	public LaneNode(Lane lane, Point point, boolean isTrafficLight) {
		this.lane = lane;
		this.point = point;
		this.isTrafficLight = isTrafficLight;
	}
	
	public double distanceTo(LaneNode other) {
		return point.distance(other.point);
	}
	
	public Point2D interpolate(LaneNode other, float d) {
		return new Point2D.Double(point.x + (other.point.x - point.x) * d,
						   		  point.y + (other.point.y - point.y) * d);
	}
	
	public void addNext(Point point) { addNext(point, false); }
	
	public void addNext(Point point, boolean isTrafficLight) {
		next = new LaneNode(lane, point, isTrafficLight);
	}
	
	public Point getPoint() { return point; }

	public LaneNode getNext() { return next; }
	
	public boolean isTrafficLight() { return isTrafficLight; }


}
